package com.netease.j;

import android.net.Uri;
import com.netease.a.a.g;
import com.netease.framework.a.j;
import com.netease.framework.a.m;
import com.netease.pris.a.t;
import com.netease.pris.a.u;
import com.netease.pris.protocol.l;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;
import junit.framework.Assert;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

public class d
  implements f
{
  static HashMap a = new HashMap();
  static int j = 0;
  private static final String l = "Http";
  private static final int m = 4096;
  m b;
  HttpClient c;
  InputStream d;
  HttpRequestBase e = null;
  j f = new j();
  byte[] g;
  int h = -1;
  boolean i;

  public d(HttpClient paramHttpClient)
  {
    this.c = paramHttpClient;
  }

  public static f a(HttpClient paramHttpClient, m paramm)
  {
    d locald = new d(paramHttpClient);
    locald.a(paramm);
    return locald;
  }

  private HttpResponse a(HttpRequestBase paramHttpRequestBase)
  {
    if (paramHttpRequestBase == null)
      throw new Exception();
    if (this.i)
      throw new IOException("Http closed");
    Object localObject2;
    try
    {
      HttpResponse localHttpResponse2 = this.c.execute(paramHttpRequestBase);
      localObject2 = localHttpResponse2;
      if (this.i)
      {
        l();
        throw new IOException("close after execute");
      }
    }
    catch (NullPointerException localNullPointerException)
    {
      if (this.i)
      {
        l();
        throw localNullPointerException;
      }
    }
    finally
    {
      if (this.i)
      {
        l();
        throw new IOException("close after execute");
        HttpResponse localHttpResponse1 = this.c.execute(paramHttpRequestBase);
        localObject2 = localHttpResponse1;
        if (!this.i)
          break label141;
        l();
        throw new IOException("close after execute");
      }
    }
    label141: return (HttpResponse)localObject2;
  }

  private void a(InputStream paramInputStream, OutputStream paramOutputStream, int paramInt)
  {
    byte[] arrayOfByte = new byte[4096];
    int k = 0;
    int n = 0;
    while ((n < paramInt) && (!this.i))
    {
      int i1 = paramInputStream.read(arrayOfByte, k, Math.min(arrayOfByte.length - k, paramInt - n));
      if (i1 == -1)
        throw new IOException("http readData from stream num mismatch");
      k += i1;
      n += i1;
      if (k != 4096)
        continue;
      paramOutputStream.write(arrayOfByte, 0, 4096);
      k = 0;
    }
    if (k > 0)
      paramOutputStream.write(arrayOfByte, 0, k);
    if (this.i)
      throw new IOException("http readData from stream close flg is set");
  }

  private boolean a(HttpResponse paramHttpResponse)
  {
    if ((paramHttpResponse != null) && (this.b.d()))
    {
      Header localHeader = paramHttpResponse.getFirstHeader("Set-Cookie");
      if (localHeader != null)
      {
        Uri localUri = Uri.parse(this.b.b());
        a.put(localUri.getHost(), localHeader.getValue());
      }
    }
    for (int k = 1; ; k = 0)
      return k;
  }

  public static void j()
  {
    if (a != null)
      a.clear();
  }

  private void l()
  {
  }

  private int m()
  {
    if (this.e != null)
    {
      this.e.abort();
      this.e = null;
    }
    int k = -1;
    int i1;
    switch (this.f.a())
    {
    default:
      i1 = k;
    case 2:
    case 1:
    }
    while (true)
    {
      if ((i1 == 401) && (this.b.d()))
      {
        CookieStore localCookieStore = ((DefaultHttpClient)this.c).getCookieStore();
        if (localCookieStore != null)
          localCookieStore.clear();
      }
      HttpResponse localHttpResponse = this.f.d();
      a(localHttpResponse);
      if (i1 == 401)
      {
        com.netease.framework.a.h localh = this.b.a(localHttpResponse);
        if ((this.b.d()) && (localh != null))
          this.b.b(localh.a(), localh.b());
        if (this.e != null)
        {
          this.e.abort();
          this.e = null;
        }
      }
      return i1;
      this.e = b(this.b);
      this.f.a(a(this.e));
      k = this.f.e();
      if (k == 200)
      {
        if ((!this.b.z()) || (!this.b.B()))
          break;
        g localg = com.netease.a.a.e.a(this.b, this.f.d(), o(), (int)i(), this);
        if (!this.b.x())
          com.netease.a.a.e.a(this.b.v(), localg);
        while (true)
        {
          i1 = k;
          break;
          if (localg == null)
            continue;
          this.f.a(localg.e());
        }
      }
      if (k == 401)
        break;
      this.f.a(null);
      i1 = k;
      continue;
      this.e = b(this.b);
      this.f.a(a(this.e));
      int n = this.f.e();
      if (n == 304)
      {
        if (this.b.z())
          com.netease.a.a.e.a(this.b, this.f, null, 0, false, this);
        this.f.a(null);
        i1 = n;
        continue;
      }
      if (n == 200)
      {
        if ((this.b.z()) && (this.b.B()))
          com.netease.a.a.e.a(this.b, this.f, o(), (int)i(), true, this);
        this.f.a(null);
        i1 = n;
        continue;
      }
      if (n != 401)
      {
        this.f.a(null);
        i1 = n;
        continue;
      }
      i1 = n;
    }
  }

  private InputStream n()
  {
    if (this.d == null)
      this.d = this.f.g();
    return this.d;
  }

  private InputStream o()
  {
    InputStream localInputStream = n();
    if ((localInputStream == null) || (this.i))
      throw new IOException("closed");
    com.netease.i.a locala = new com.netease.i.a(localInputStream);
    if (this.f.d() != null)
      locala.a(this.b.D());
    return locala;
  }

  private byte[] p()
  {
    InputStream localInputStream;
    Object localObject3;
    try
    {
      localInputStream = n();
      if ((localInputStream != null) && (!this.i))
        break label41;
      throw new IOException("closed");
    }
    finally
    {
      localObject3 = null;
    }
    if (localObject3 != null);
    while (true)
    {
      label41: int i1;
      long l2;
      try
      {
        localObject3.close();
        throw localObject1;
        locala = new com.netease.i.a(localInputStream);
      }
      catch (Exception localException1)
      {
        try
        {
          if (this.f.d() == null)
            continue;
          locala.a(this.b.D());
          ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
          int k = (int)this.f.f();
          if (k <= 0)
            continue;
          a(locala, localByteArrayOutputStream, k);
          byte[] arrayOfByte3 = localByteArrayOutputStream.toByteArray();
          Object localObject4 = arrayOfByte3;
          if (locala == null)
            continue;
          try
          {
            locala.close();
            return localObject4;
            l1 = System.currentTimeMillis();
            byte[] arrayOfByte1 = new byte[4096];
            int n = 0;
            if (this.i)
              continue;
            i1 = locala.read(arrayOfByte1, n, arrayOfByte1.length - n);
            l2 = System.currentTimeMillis();
            if (i1 >= 0)
              break label291;
            if (n <= 0)
              continue;
            localByteArrayOutputStream.write(arrayOfByte1, 0, n);
            if (!this.i)
              continue;
            throw new IOException("Http readData close flg is set");
            n += i1;
            if (n != 4096)
              break label311;
            localByteArrayOutputStream.write(arrayOfByte1, 0, 4096);
            n = 0;
            break label311;
            byte[] arrayOfByte2 = localByteArrayOutputStream.toByteArray();
            localObject4 = arrayOfByte2;
            if (locala == null)
              continue;
            try
            {
              locala.close();
            }
            catch (Exception localException2)
            {
            }
            continue;
          }
          catch (Exception localException3)
          {
            continue;
          }
          localException1 = localException1;
          continue;
        }
        finally
        {
          com.netease.i.a locala;
          localObject3 = locala;
        }
      }
      break;
      label291: if (i1 != 0)
        continue;
      if (l2 - l1 <= 5000L)
        continue;
      continue;
      label311: long l1 = l2;
    }
  }

  public void a(int paramInt)
  {
    this.h = paramInt;
  }

  public void a(m paramm)
  {
    this.b = paramm;
    paramm.a();
    if (paramm.w())
    {
      if (!paramm.x())
        break label42;
      this.f.a(com.netease.a.a.e.a(paramm.v(), paramm.A()));
    }
    while (true)
    {
      return;
      label42: g localg = com.netease.a.a.e.a(paramm.t(), paramm.v(), paramm.A());
      this.f.a(localg);
    }
  }

  public boolean a()
  {
    return this.i;
  }

  public int b()
  {
    int k = 200;
    try
    {
      if (!u.e(com.netease.b.a.d.h().a()))
      {
        if ((this.f.c() != null) || (this.f.b() != null))
        {
          boolean bool = com.netease.pris.c.h.b(com.netease.b.a.d.h().a(), com.netease.b.a.d.h().c(), com.netease.b.a.d.h().d());
          if (bool)
          {
            if (!this.i)
              break label443;
            e();
            throw new IOException("http execute closed");
          }
        }
        throw new com.netease.framework.a.e();
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      throw localException;
    }
    finally
    {
      if (this.i)
      {
        e();
        throw new IOException("http execute closed");
        if ((0x2 & this.b.h()) != 0)
        {
          com.netease.l.c.a locala = com.netease.b.a.d.h().b();
          if ((locala == null) || (!locala.a("system_setting_offline", false)))
          {
            t localt = u.c(com.netease.b.a.d.h().a());
            if ((localt == t.d) || (localt == t.c))
              throw new com.netease.e.a();
          }
        }
        if (com.netease.pris.app.e.a)
          com.netease.g.b.e("Http", "execute url is:" + this.b.b());
        int n = m();
        if ((n == 401) && (this.b.d()))
        {
          n = m();
          if (n == k)
          {
            com.netease.b.a.d.h().a(com.netease.h.b.d);
            com.netease.pris.d.c.a(0L, com.netease.b.a.d.h().c());
          }
        }
        int i1 = n;
        if (i1 == 401)
          this.f.a(null);
        while (true)
          if (this.f != null)
          {
            int i2 = this.f.e();
            k = i2;
            if (!this.i)
              break;
            e();
            throw new IOException("http execute closed");
            if (i1 != 403)
              continue;
            Header localHeader = this.f.d().getFirstHeader("X-Error");
            if (localHeader == null)
              continue;
            com.netease.g.b.d("403 X-Error", "" + localHeader.getValue());
            continue;
          }
          else
          {
            k = -1;
            if (!this.i)
              break;
            e();
            throw new IOException("http execute closed");
          }
      }
    }
    label443: return k;
  }

  HttpRequestBase b(m paramm)
  {
    Object localObject;
    if (paramm.o() == com.netease.framework.a.b.a)
      localObject = new HttpGet();
    URI localURI;
    while (true)
    {
      localURI = URI.create(paramm.b());
      ((HttpRequestBase)localObject).setURI(localURI);
      ((HttpRequestBase)localObject).setParams(c(paramm));
      List localList = paramm.s();
      if (localList == null)
        break;
      Iterator localIterator = localList.iterator();
      while (localIterator.hasNext())
      {
        com.netease.framework.a.h localh = (com.netease.framework.a.h)localIterator.next();
        ((HttpRequestBase)localObject).addHeader(localh.a(), localh.b());
      }
      if (paramm.o() == com.netease.framework.a.b.e)
      {
        localObject = new HttpHead();
        continue;
      }
      if (paramm.o() == com.netease.framework.a.b.b)
      {
        HttpPost localHttpPost = new HttpPost();
        HttpEntity localHttpEntity1 = paramm.p();
        if (localHttpEntity1 != null)
          localHttpPost.setEntity(localHttpEntity1);
        localObject = localHttpPost;
        continue;
      }
      if (paramm.o() == com.netease.framework.a.b.c)
      {
        HttpPut localHttpPut = new HttpPut();
        HttpEntity localHttpEntity2 = paramm.p();
        if (localHttpEntity2 != null)
          localHttpPut.setEntity(localHttpEntity2);
        localObject = localHttpPut;
        continue;
      }
      if (paramm.o() == com.netease.framework.a.b.f)
      {
        localObject = new HttpOptions();
        continue;
      }
      if (paramm.o() == com.netease.framework.a.b.d)
      {
        localObject = new HttpDelete();
        continue;
      }
      Assert.assertTrue(false);
      localObject = null;
    }
    if (paramm.d())
    {
      String str1 = localURI.getHost();
      String str2 = (String)a.get(str1);
      if (str2 != null)
        ((HttpRequestBase)localObject).addHeader("Cookie", str2);
    }
    if ((this.f.a() == 1) && (this.f.h() != null))
      ((HttpRequestBase)localObject).addHeader("If-Modified-Since", this.f.h());
    return (HttpRequestBase)localObject;
  }

  HttpParams c(m paramm)
  {
    BasicHttpParams localBasicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(localBasicHttpParams, l.c);
    return localBasicHttpParams;
  }

  public void c()
  {
    if ((!this.i) && (this.g != null) && (this.f.d() != null) && (this.b.z()) && (!this.b.B()))
      try
      {
        if (this.f.b() != null)
        {
          if (this.f.e() == 200)
            com.netease.a.a.e.a(this.b, this.f, new ByteArrayInputStream(this.g), this.g.length, true, this);
        }
        else
        {
          localg = com.netease.a.a.e.a(this.b, this.f.d(), new ByteArrayInputStream(this.g), this.g.length, this);
          if (!this.b.x())
            com.netease.a.a.e.a(this.b.v(), localg);
        }
      }
      catch (com.netease.a.a.d locald)
      {
        g localg;
        locald.printStackTrace();
        return;
        if (localg != null)
          this.f.a(localg.e());
      }
      catch (com.netease.k.c localc)
      {
        localc.printStackTrace();
      }
  }

  public int d()
  {
    if (this.f != null);
    for (int k = this.f.e(); ; k = -1)
      return k;
  }

  public void e()
  {
    this.i = true;
    if (this.e != null)
    {
      this.e.abort();
      this.e = null;
    }
    if (this.d != null);
    try
    {
      this.d.close();
      this.d = null;
      l();
      this.g = null;
      if (this.f != null)
      {
        this.f.a(null);
        this.f.a(null);
      }
      return;
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }
  }

  public byte[] f()
  {
    if (this.g == null)
      this.g = p();
    return this.g;
  }

  public String g()
  {
    String str;
    if (this.f != null)
      if ((this.b.y()) && (this.f.c() != null))
        str = "gzip";
    while (true)
    {
      return str;
      str = this.f.i();
      continue;
      str = null;
    }
  }

  public String h()
  {
    if (this.f != null);
    for (String str = this.f.j(); ; str = null)
      return str;
  }

  public long i()
  {
    long l1;
    if (this.f != null)
      l1 = this.f.f();
    while (true)
    {
      return l1;
      l1 = -1L;
    }
  }

  public Object k()
  {
    String str = g();
    Object localObject;
    if ((str != null) && ("gzip".equals(str)))
    {
      byte[] arrayOfByte = f();
      if (arrayOfByte != null)
        localObject = new GZIPInputStream(new com.netease.i.a(new ByteArrayInputStream(arrayOfByte)));
    }
    while (true)
    {
      return localObject;
      localObject = null;
      continue;
      localObject = f();
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.j.d
 * JD-Core Version:    0.6.0
 */